$(function(){
  // 1.发起ajax请求
    // 定义请求数据
  const data = {
    pageNum:1,
    pageSize:30,

  }
  getAjaxList()
  function getAjaxList(){
  $.ajax({
    method:'GET',
    url:'http://124.223.14.236:3001/api/recipe',
    data,
    success:function(res) {
      if(!res.success) return layer.msg('请求列表数据失败')
      render(res.data.list)
    }
  })
 }

  // 2.定义渲染函数
  function render(data) {
    let str = ''

    data.forEach((item,index) => {
      const {id , img , name} = item
      str += `
        <li>
          <a href="info.html?id=${id}">
            <img src="http://124.223.14.236:3001/public/${img}" alt="" />
            <h3>${name}</h3>
          </a>
        </li>
      `
    })
   $('.list-box').html(str) 
  }
})